/**
 * 表单验证
 * 
 * @param {Object} rules 验证字段的规则
 * @param {Object} messages 验证字段的提示信息
 * 
 */

import basic from './basic.js';
var actmodel = new basic();
actmodel.do = "my_center"
actmodel.offset = function (that, reset, para, xcsorts) { 
  if(!xcsorts)
  {
    xcsorts=[["id", "desc"], ["createtime", "desc"]] ;
  }
  var acturlpara = {};   
  acturlpara["url"] = "entry/wxapp/"+actmodel.do
  if (para) {
    para["op"] = "offset"
    para["plugin"] = "integral"
  }
  else {
    this.wherepara["op"] = "offset"
    this.wherepara["plugin"] = "integral"
  }
  return actmodel.pagelist(acturlpara, that, reset, para, xcsorts);
}

actmodel.setclub = function (clubid) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "setclub" };
    var postdata = { clubid: clubid }
    this.post(urlpara, postdata).then(res => {

      resolve(res)

    })
  })
}
actmodel.getmycloubinfo = function (clubid,op) {
  
  if(!clubid)
  {
    clubid=0
  }
 
  //op
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "mycloubinfo",clubid };
    var postdata = { }
    this.post(urlpara, postdata).then(res => {
      resolve(res)
    })
  })
}
actmodel.simplevipinfo = function () {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "simplevipinfo" };
    var postdata = { }
    this.post(urlpara, postdata).then(res => {
      if(res["status"]==1){

        var app= getApp();

        if(res["obj"]&&app.globalData.member && app.globalData.member.memberinfo){

          app.globalData.member.memberinfo["amount"]=res["obj"]["amount"]
          app.globalData.member.memberinfo["money"]=res["obj"]["money"]
          app.globalData.member.memberinfo["score"]=res["obj"]["score"]
          app.globalData.member.memberinfo["totalmoney"]=res["obj"]["totalmoney"]
          app.globalData.member.memberinfo["vips"]=res["obj"]["vips"]
        }
    
      }
      resolve(res)
    })
  })
}

actmodel.balacerecharge = function (model) {
  return new Promise((resolve) => {
    var urlpara = { do: "user_center", op: "balacerecharge" };
    var postdata = { model: JSON.stringify(model) }
    this.post(urlpara, postdata).then(res => {
      resolve(res)
    })
  })
}
module.exports = actmodel;